<template>
	<yd-layout id='bdStudyStage' class=''>
		<img class="header_img" :src="levelObj.title_img" alt="" />
		<template v-if="levelObj&&levelObj!='{}'">
			<div class="header" @click="goStageList" v-if='levelObj.passed===1'>
				<div class="header_left" >
					<div  class="header_title c_size_34_48" style="color: #DCBBC9;">太棒了，你已通过测评~</div>
					<div  class="header_label">看看你的测评记录吧~</div>
				</div>
				<div class="header_btn" >去看看</div>
			</div>
			<div class="header" v-else @click="goStageState">
				<div class="header_left" >
					<div class="header_title c_size_34_48">参与学习测评</div>
					<div  class="header_label">考核通过后才可学习下阶段课程哦~</div>
				</div>
				<div class="header_btn" >
					去测评
				</div>
			</div>
		</template>
		
		<div class="content">
			<div class="title">
				<div class="c_size_34_48">课程目录</div>
				<span>共{{courseList.length}}节课程</span>
			</div>
			<div class="list">
				<div class="list_item" v-for="item,index in courseList" @click="goNext(item)">
					<img src="../../../assets/my_4.png" alt="" />
					<div class="item_right">
						<div :style="{color:item.learned==1?'#999999':'#333333'}" class="item_title c_size_34_48">{{item.title}}</div>
						<div class="item_content">
							<div>{{item.play_count}}次学习</div>
							<span v-if="item.learned==1"></span>
							<div v-if="item.learned==1">已学</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</yd-layout>
</template>

<script>
	export default{
		components:{
			
		},
		data(){
			return {
				levelObj:{},
				courseList:[],
			}
		},
		created() {
		},
		watch: {
			
		},
		computed: {
			
		},
		async mounted(){
//			if(this.$route.query.channel){
				//不能通过channel判断，因为可能是网页登录
			var flg =	await this.isActive()
//			}
			if(flg){
				this.getLevel()
			}
			
		},
		methods:{
			isActive(){
				return new Promise((resolve,reject)=>{
					this.$root.ajax({
						name:'bible/isActive',
						type:'get',
						closeAllLoading:true,
						params: {}
					}).then((d) => {
						if(d.data){
							resolve(true)
						}else{
							this.$router.push({
								name:'bd_index'
							})
						}
						
					})
				})
			},
			//阶段课程目录
			getLevel(){
				this.$root.ajax({
					name: 'bible/level',
					type:'get',
					params: {
						id:this.$route.query.id
					}
				}).then((d) => {
					this.levelObj=Object.assign({},this.levelObj,d.data.level)
					this.courseList=d.data.course_list
					document.title=d.data.level.name
					
					//分享
					if(this.$root.isWeiXin()){
						//分享
						let query = '';
						if(this.$root.config.channel){
						 	query = `params=channelDY2FGoldUrlStrDY${this.$route.name}FGkeyNumDY1FGparamsKey1DYidFGparamsVal1DY${this.levelObj.id}`
						}else{
						 	query = `params=channelDY2FGoldUrlStrDY${this.$route.name}FGkeyNumDY1FGparamsKey1DYidFGparamsVal1DY${this.levelObj.id}`
						}
						this.$root.wxShare({
							d:{title:this.levelObj.title,title_img:this.$root.config.shareImg},//分享对象，题目等{title:'',title-img:''}
							query: query,//参数
							desc:`新人起步宝典${this.levelObj.name}`//分享详情
						})
					}
				})
			},
			goNext(item){
				if(this.levelObj.pre_passed==1){
					this.$router.push({
						name:'bd_studyStageDetailVideo',
						query:{
							id:item.id
						}
					})
				}else{
					this.$dialog.confirm({
	                    title: '温馨提示',
	                    mes: '未通过前面的课程测评，请完成测评后再学习后续课程',
	                    opts: [
	                        {
	                            txt: '我知道了',
	                            color: '#DCBBC9',
	                            callback: () => {
	                            	
	                            }
	                        }
	                    ]
	                });
				}
				
			},
			goStageState(){
				if(this.levelObj.pre_passed==1){
					this.$router.push({
						name:'bd_stageState',
						query:{
							id:this.levelObj.id
						}
					})
				}else{
					this.$dialog.confirm({
	                    title: '温馨提示',
	                    mes: '亲爱的学员，上阶段的学习测评你尚未通过，请完成测评后再学习后续课程',
	                    opts: [
	                        {
	                            txt: '我知道了',
	                            color: '#DCBBC9',
	                            callback: () => {
	                            	
	                            }
	                        }
	                    ]
	                });
				}
				
			},
			goStageList(){
				this.$router.push({
					name:'bd_stageList',
					query:{
						level_id:this.levelObj.id
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	@import './studyStage.scss';
</style>